//
//  FLLPresentTableViewCell.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/7.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLPresentTableViewCell.h"
#import "FLLPresentCollectionViewCell.h"
#import "FLLMacro.h"
#import "FLLPresentFirstCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "FLLPresentTopicsCollectionViewCell.h"
#import "PresentShequ_Topics.h"

@interface FLLPresentTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end
@implementation FLLPresentTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    [self createPresentCollectionView];
    
}
- (void)createPresentCollectionView
{
    _presentLayout.minimumInteritemSpacing = CellMargin;
    _presentLayout.minimumLineSpacing = CellMargin;
    _presentLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    _presentLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    _presentCollectionView.delegate = self;
    _presentCollectionView.dataSource = self;
    _presentCollectionView.showsHorizontalScrollIndicator = NO;
    _presentCollectionView.backgroundColor = [UIColor whiteColor];
    [_presentCollectionView registerNib:[UINib nibWithNibName:@"FLLPresentCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"presentCollectionCell"];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    
    return _topicsArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{


    FLLPresentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"presentCollectionCell" forIndexPath:indexPath];
    [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:_topicsArray[indexPath.row].image] placeholderImage:[UIImage new] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    
    return cell;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemWidth = (_presentCollectionView.bounds.size.width - 2 * CellMargin) / 3.0;
    CGFloat itemHeight = _presentCollectionView.bounds.size.height;
    return CGSizeMake(itemWidth, itemHeight);
}
- (void)setTopicsArray:(NSArray<PresentSecData *> *)topicsArray
{
    _topicsArray = topicsArray;
    [self.presentCollectionView reloadData];
         
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    self.idBlock(_topicsArray[indexPath.row].id_Data);
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
